from .db import mySQLConnectionPool
from flask import Flask


class myAppFactory:
    def __init__(self, test_config=None):
        self._app = None
        self._config = test_config
        self.__pool = mySQLConnectionPool()

    @property
    def create_app(self):
        self._app = Flask(__name__, instance_relative_config=True)
    
        self._app.config.from_mapping(
            SECRET_KEY = 'dev'
        )

        if self._config is None:
            self._app.config.from_pyfile('config.py', silent=True)
        else:
            self._app.config.from_mapping(self._config)
        
        # 注册钩子
        self.__pool.init_app(self._app)

        return self._app
        
